home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Aminet 5
/
Aminet 5 - March 1995.iso
/
Aminet
/
mus
/
edit
/
AlgoRhythms.lha
/
AlgoRhythms
/
Source
/
voices.c
< prev
next >
Wrap
C/C++ Source or Header
|
1994-11-25
|
11KB
|
366 lines
/* voices.c
Copyright (c) 1993 by Thomas E. Janzen
All Rights Reserved
THIS SOFTWARE IS FURNISHED FREE OF CHARGE FOR STUDY AND USE AND MAY
BE COPIED ONLY FOR PERSONAL USE OR COMPLETELY AS OFFERED WITH NO
CHANGES FOR FREE DISTRIBUTION. NO TITLE TO AND OWNERSHIP OF THE
SOFTWARE IS HEREBY TRANSFERRED. THOMAS E. JANZEN ASSUMES NO
RESPONSIBILITY FOR THE USE OR RELIABILITY OF THIS SOFTWARE.
Thomas E. Janzen
208A Olde Derby Road
Norwood, MA 02062-1761
(617)769-7733
** FACILITY:
**
** AlgoRhythms music improviser on Commodore (TM) Amiga (TM)
** compiled with SAS/C Amiga Compiler 6.50
**
** ABSTRACT:
**
** voices.c supports gadgets (using GadTools) for controlling one
** voice's set up at a time.
**
** AUTHORS: Thomas E. Janzen
**
** CREATION DATE: 23-OCT-1993
**
** MODIFICATION HISTORY:
** DATE NAME DESCRIPTION
** 1 JAN 93 TEJ New for V3.0
**--
*/
#define INTUI_V36_NAMES_ONLY
#include <stdlib.h>
#include <stdio.h>
#include <ctype.h>
#include <string.h>
#include <exec/types.h>
#include <exec/nodes.h>
#include <intuition/intuition.h>
#include <libraries/gadtools.h>
#include <clib/exec_protos.h>
#include <clib/graphics_protos.h>
#include <clib/intuition_protos.h>
#include <clib/gadtools_protos.h>
#include <clib/utility_protos.h>
#include <clib/dos_protos.h>
#include <proto/graphics.h>
#include <proto/intuition.h>
#include <proto/gadtools.h>
#include "window.h"
#include "voices.h"
#include "algorhythms.h"
#include "pitchnames.h"
#define C_MELODY_X (100)
#define C_MELODY_Y (24)
#define C_MIDI_X (100)
#define C_MIDI_Y (36)
#define C_LOW_X (100)
#define C_LOW_Y (60)
#define C_HIGH_X (100)
#define C_HIGH_Y (48)
#define C_VOICE_X (100)
#define C_VOICE_Y (12)
#define C_CHAN_X (205)
#define C_CHAN_Y (24)
#define GAD_VOICE (0)
#define GAD_CHAN (1)
#define GAD_MELODY (2)
#define GAD_LOW_NOTE (3)
#define GAD_HIGH_NOTE (4)
#define GAD_MIDI (5)
#define GAD_LAST (6)
#define C_INNER_WINDOW (625)
static char
*melody_str[] = {"Random", "Walking", NULL},
*midi_str[] = {"Midi", "Audio", NULL},
*voice_str[] = { "1", "2", "3", "4", "5", "6", "7", "8", "9",
"10", "11", "12", "13", "14", "15", "16",
"17", "18", "19", "20", NULL};
static struct Node chan_nodes[18]
= {{&chan_nodes[1], NULL, 0, 0, NULL},
{&chan_nodes[2], &chan_nodes[0], 0, 0, " 1"},
{&chan_nodes[3], &chan_nodes[1], 0, 0, " 2"},
{&chan_nodes[4], &chan_nodes[2], 0, 0, " 3"},
{&chan_nodes[5], &chan_nodes[3], 0, 0, " 4"},
{&chan_nodes[6], &chan_nodes[4], 0, 0, " 5"},
{&chan_nodes[7], &chan_nodes[5], 0, 0, " 6"},
{&chan_nodes[8], &chan_nodes[6], 0, 0, " 7"},
{&chan_nodes[9], &chan_nodes[7], 0, 0, " 8"},
{&chan_nodes[10], &chan_nodes[8], 0, 0, " 9"},
{&chan_nodes[11], &chan_nodes[9], 0, 0, "10"},
{&chan_nodes[12], &chan_nodes[10], 0, 0, "11"},
{&chan_nodes[13], &chan_nodes[11], 0, 0, "12"},
{&chan_nodes[14], &chan_nodes[12], 0, 0, "13"},
{&chan_nodes[15], &chan_nodes[13], 0, 0, "14"},
{&chan_nodes[16], &chan_nodes[14], 0, 0, "15"},
{&chan_nodes[17], &chan_nodes[15], 0, 0, "16"},
{NULL, &chan_nodes[16], 0, 0, NULL}};
static struct Window *voice_wind = NULL;
static struct Gadget *glist = NULL,
*voice_gads[GAD_LAST];
ULONG voices_mask = 0;
static int current_voice = 0;
static struct Gadget *create_voice_gadgets(UWORD topborder);
static void voice_event(struct Gadget *gad, UWORD code,
NOTE_EVENT_TYPE *events);
static void voice_event(struct Gadget *gad, UWORD code,
NOTE_EVENT_TYPE *events)
{
switch (gad->GadgetID)
{
case GAD_VOICE:
current_voice = code;
set_voice_gadgets(events);
break;
case GAD_CHAN:
events[current_voice].nv_i_channel = code;
break;
case GAD_MELODY:
events[current_voice].nv_i_walking = code;
break;
case GAD_LOW_NOTE:
events[current_voice].nv_i_low_pitch
= pitch_to_midi
(((struct StringInfo *)(gad->SpecialInfo))->Buffer);
break;
case GAD_HIGH_NOTE:
events[current_voice].nv_i_high_pitch
= pitch_to_midi(((struct StringInfo *)
(gad->SpecialInfo))->Buffer);
break;
case GAD_MIDI:
events[current_voice].nv_i_audio = code;
break;
default:
break;
}
return;
}
static struct Gadget *create_voice_gadgets(UWORD topborder)
{
auto struct TagItem high_low_items[] ={{GTST_String, (ULONG)"A#1"},
{GTST_MaxChars, 10}, {TAG_END, 0L}};
auto struct NewGadget ng;
auto struct Gadget *gad;
gad = CreateContext(&glist);
ng.ng_Height = 12;
ng.ng_TextAttr = &font_choice;
ng.ng_VisualInfo = vi;
/*
** Set up Voice selection
*/
ng.ng_LeftEdge = C_VOICE_X;
ng.ng_TopEdge = C_VOICE_Y;
ng.ng_Width = 100;
ng.ng_Height = 12;
ng.ng_GadgetText = "VOICE";
ng.ng_GadgetID = GAD_VOICE;
ng.ng_Flags = NG_HIGHLABEL | PLACETEXT_LEFT;
voice_gads[GAD_VOICE]
= gad
= CreateGadget(CYCLE_KIND, gad, &ng, GTCY_Labels, voice_str,
TAG_END);
/*
** Set up chan list
*/
ng.ng_LeftEdge = C_CHAN_X;
ng.ng_TopEdge = C_CHAN_Y;
ng.ng_Width = 65;
ng.ng_Height = 52;
ng.ng_GadgetText = "Channel";
ng.ng_GadgetID = GAD_CHAN;
ng.ng_Flags = PLACETEXT_ABOVE;
voice_gads[GAD_CHAN] = gad = CreateGadget(LISTVIEW_KIND, gad, &ng,
GTLV_Labels, chan_nodes, GTLV_ShowSelected, NULL, TAG_END);
/*
** Set up Melody random/walking
*/
ng.ng_LeftEdge = C_MELODY_X;
ng.ng_TopEdge = C_MELODY_Y;
ng.ng_Width = 100;
ng.ng_Height = 12;
ng.ng_GadgetText = "Melody";
ng.ng_Flags = PLACETEXT_LEFT;
ng.ng_GadgetID = GAD_MELODY;
voice_gads[GAD_MELODY]
= gad
= CreateGadget(CYCLE_KIND, gad, &ng, GTCY_Labels, melody_str,
TAG_END, 0L);
/*
** Set up low note
*/
ng.ng_LeftEdge = C_LOW_X;
ng.ng_TopEdge = C_LOW_Y;
ng.ng_Width = 100;
ng.ng_GadgetText = "Low Note";
ng.ng_GadgetID = GAD_LOW_NOTE;
ng.ng_Flags = PLACETEXT_LEFT;
voice_gads[GAD_LOW_NOTE] = gad
= CreateGadgetA(STRING_KIND, gad, &ng, high_low_items);
/*
** Set up high note
*/
ng.ng_LeftEdge = C_HIGH_X;
ng.ng_TopEdge = C_HIGH_Y;
ng.ng_Width = 100;
ng.ng_GadgetText = "High Note";
ng.ng_Flags = PLACETEXT_LEFT;
ng.ng_GadgetID = GAD_HIGH_NOTE;
voice_gads[GAD_HIGH_NOTE] = gad
= CreateGadgetA(STRING_KIND, gad, &ng, high_low_items);
/*
** Set up Audio/MIDI
*/
ng.ng_LeftEdge = C_MIDI_X;
ng.ng_TopEdge = C_MIDI_Y;
ng.ng_Width = 100;
ng.ng_GadgetText = "MIDI/Audio";
ng.ng_GadgetID = GAD_MIDI;
ng.ng_Flags = PLACETEXT_LEFT;
voice_gads[GAD_MIDI]
= gad
= CreateGadget(CYCLE_KIND, gad, &ng, GTCY_Labels, midi_str,
TAG_END);
return gad;
}
int process_voice_events(NOTE_EVENT_TYPE *chairs)
{
auto int result = 0,
Closing = FALSE;
auto ULONG imsgClass;
auto UWORD imsgCode;
auto struct Gadget *gad;
auto struct IntuiMessage *imsg;
while (imsg = GT_GetIMsg(voice_wind->UserPort))
{
gad = (struct Gadget *)imsg->IAddress;
imsgClass = imsg->Class;
imsgCode = imsg->Code;
GT_ReplyIMsg(imsg);
switch(imsgClass)
{
case IDCMP_CLOSEWINDOW:
Closing = TRUE;
break;
case IDCMP_GADGETDOWN:
case IDCMP_MOUSEMOVE:
case IDCMP_GADGETUP:
voice_event(gad, imsgCode, chairs);
result = 1;
break;
case IDCMP_REFRESHWINDOW:
GT_BeginRefresh(voice_wind);
GT_RefreshWindow(voice_wind, NULL);
GT_EndRefresh(voice_wind, TRUE);
break;
}
}
if (Closing)
{
close_voices();
}
return result;
}
void open_voices_window(void)
{
auto UWORD topborder;
if (voice_wind != NULL)
{
return;
}
topborder = main_screen->WBorTop
+ (main_screen->Font->ta_YSize + 1);
if (NULL == create_voice_gadgets(topborder))
{
;
}
else
{
if (NULL == (voice_wind = OpenWindowTags(NULL,
WA_Title, "VOICE",
WA_Left, 200L,
WA_Gadgets, glist, WA_AutoAdjust, TRUE,
WA_Width, 276, WA_MinWidth, 290,
WA_InnerHeight, 61, WA_MinHeight, 71,
WA_DragBar, TRUE, WA_DepthGadget, TRUE,
WA_Activate, TRUE,
#if 0
WA_CloseGadget, TRUE,
#endif
WA_SimpleRefresh, TRUE,
WA_IDCMP, /* IDCMP_CLOSEWINDOW | */ IDCMP_REFRESHWINDOW
| STRINGIDCMP | BUTTONIDCMP | LISTVIEWIDCMP,
WA_CustomScreen, main_screen, TAG_END)))
{
;
}
else
{
GT_RefreshWindow(voice_wind, NULL);
voices_mask = 1 << voice_wind->UserPort->mp_SigBit;
}
}
return;
}
void close_voices(void)
{
RemoveGList(voice_wind, glist, -1);
CloseWindowSafely(voice_wind);
voice_wind = NULL;
FreeGadgets(glist);
glist = NULL;
return;
}
void set_voice_gadgets(NOTE_EVENT_TYPE *chairs)
{
auto char temp_str[80];
GT_SetGadgetAttrs(voice_gads[GAD_CHAN], voice_wind, NULL,
GTLV_Selected, chairs[current_voice].nv_i_channel, TAG_END, 0L);
GT_SetGadgetAttrs(voice_gads[GAD_MELODY], voice_wind, NULL,
GTCY_Active, chairs[current_voice].nv_i_walking, TAG_END, 0L);
midi_to_pitch(chairs[current_voice].nv_i_low_pitch, temp_str);
GT_SetGadgetAttrs(voice_gads[GAD_LOW_NOTE], voice_wind, NULL,
GTST_String, temp_str, TAG_END, 0L);
midi_to_pitch(chairs[current_voice].nv_i_high_pitch, temp_str);
GT_SetGadgetAttrs(voice_gads[GAD_HIGH_NOTE], voice_wind, NULL,
GTST_String, temp_str, TAG_END, 0L);
GT_SetGadgetAttrs(voice_gads[GAD_MIDI], voice_wind, NULL,
GTCY_Active, chairs[current_voice].nv_i_audio, TAG_END, 0L);
RefreshGadgets(glist, voice_wind, NULL);
return;
}
int get_current_voice(void)
{
return current_voice;
}